import ee3
import clr
import ee3_gui
clr.AddReferenceByPartialName("PresentationCore")
clr.AddReferenceByPartialName("PresentationFramework")
clr.AddReferenceByPartialName("WindowsBase")
clr.AddReference('System.Windows.Forms')
from System.Windows.Forms import *
from System.Windows.Controls import *
from System import *

class parallel(object):
    def onTick(self, sender, event):
        self.counter.Content = int(self.counter.Content) + 1
 
    def __init__(self, port):
        self.port = port
        self.serijska = ""
        self.procesna = ""
        self.komentar = ""
        self.error = ""
        self.warning = ""
        self.info = ""
        self.ok = ""
        self.counter = Label()
        self.counter.Content = "0"

        self.status = ""
        self.id = None

        self.timer = Timer()
        self.timer.Interval = 1000
        self.timer.Tick += self.onTick

    def zacetek_testa(self):
        self.counter.Content = "0"
        self.timer.Start()
        if (self.error == ''):
            ee3.obrazec.tabItem3.IsEnabled = 0
            ee3.obrazec.button_green.IsEnabled = 1
            ee3.obrazec.button_red.IsEnabled = 1

    def konec_testa(self):
        ee3.obrazec.tabItem3.IsEnabled = 1
        self.timer.Stop()
    
    def osvezi_znake(self):
        ee3_gui.brisiznake()
        ee3_gui.narisiznake(self.error, self.warning, self.info, self.ok)

    def prikazi_na_obrazcu(self):
        ee3.obrazec.stackPanel5.Children.RemoveAt(3)
        ee3.obrazec.stackPanel5.Children.Add(self.counter)
        ee3.obrazec.label1_procesna_vobdelavi.Text = self.procesna
        ee3.obrazec.label1_serijska_vobdelavi.Text = self.serijska
        ee3.obrazec.label1_rezultat_vobdelavi.Text = self.komentar
        self.osvezi_znake()
        self.pass_fail_napake(self.status)

    def info_setter(self, value):
        self.info = value
        ee3_gui.brisiznake()
        ee3_gui.narisiznake(self.error, self.warning, self.info, self.ok)
    def info_getter(self):
        return self.info
    plosca_info = property(info_getter, info_setter)
    def error_setter(self, value):
        self.error = value
        ee3_gui.brisiznake()
        ee3_gui.narisiznake(self.error, self.warning, self.info, self.ok)
    def error_getter(self):
        return self.error
    plosca_error = property(error_getter, error_setter)
    def warning_setter(self, value):
        self.warning = value
        ee3_gui.brisiznake()
        ee3_gui.narisiznake(self.error, self.warning, self.info, self.ok)
    def warning_getter(self):
        return self.warning
    plosca_warning = property(warning_getter, warning_setter)
    def ok_setter(self, value):
        self.ok = value
        ee3_gui.brisiznake()
        ee3_gui.narisiznake(self.error, self.warning, self.info, self.ok)
    def ok_getter(self):
        return self.ok
    plosca_ok = property(ok_getter, ok_setter)

    # kontrolira gumbe pass, fail in tab napake
    def pass_fail_napake(self, status):
        if (self.status == "TESTING"):
            ee3.obrazec.tabItem3.IsEnabled = 0
            ee3.obrazec.button_green.IsEnabled = 1
            ee3.obrazec.button_red.IsEnabled = 1
        elif (self.status == "FINISH"):
            ee3.obrazec.tabItem3.IsEnabled = 1
            ee3.obrazec.button_green.IsEnabled = 0
            ee3.obrazec.button_red.IsEnabled = 0
        elif (self.status == "INIT"):
            ee3.obrazec.tabItem3.IsEnabled = 0
            ee3.obrazec.button_green.IsEnabled = 0
            ee3.obrazec.button_red.IsEnabled = 0
        elif (self.status == "ERROR"):
            ee3.obrazec.tabItem3.IsEnabled = 0
            ee3.obrazec.button_green.IsEnabled = 0
            ee3.obrazec.button_red.IsEnabled = 0

    def status_setter(self, value):
        self.status = value
        if (value == "TESTING"):
            self.zacetek_testa()
        elif (value == "FINISH"):
            self.konec_testa()
        self.pass_fail_napake(value)
        ee3_gui.brisiznake()
        ee3_gui.narisiznake(self.error, self.warning, self.info, self.ok)
    def status_getter(self):
        return self.status
    plosca_status = property(status_getter, status_setter)